import 'package:canteen/userDetail.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:canteen/edit_c_v.dart';

class ChoosePage extends StatefulWidget {
  @override
  State<ChoosePage> createState() => _ChoosePageState();
}

class _ChoosePageState extends State<ChoosePage> {
  late String _selectedOption;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _selectedOption = options.first;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 280,
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              TextButton(
                onPressed: () {
                  Navigator.of(context).pop();
                },
                child: Text(
                  '取消',
                  style: TextStyle(color: Colors.blueAccent, fontSize: 14),
                ),
              ),
              TextButton(
                onPressed: () {
                  setState(() {
                    if (options.first == '员工') {
                      staffType = _selectedOption;
                    } else if (options==departments) {
                      department = _selectedOption;
                    }  else {
                      category = _selectedOption;
                    }
                  });
                  Navigator.of(context).pop();
                },
                child: Text(
                  '确定',
                  style: TextStyle(color: Colors.redAccent, fontSize: 14),
                ),
              ),
            ],
          ),
          Expanded(
            child: CupertinoPicker(
              itemExtent: 32.0,
              onSelectedItemChanged: (index) {
                _selectedOption = options[index];
              },
              children: options
                  .map(
                    (option) => Text(
                      option,
                    ),
                  )
                  .toList(),
            ),
          ),
        ],
      ),
    );
  }
}
